'use strict';
const db = uniCloud.database()
exports.main = async (event, context) => {
	//event为客户端上传的参数
	console.log('event : ', event)
	const openAllQlist = async () => {

		// const subjectPageList = await db.collection('subject-page').field({
		// 	_id: true,
		// 	s_id: true
		// }).limit(500).get()
		// const mechinsmList = await db.collection('mechanism').field({
		// 	_id: true,
		// 	s_id: true
		// }).limit(500).get()
		const curHasMec = await db.collection('mechanism-subject-list').field({
			_id: true,
			subject_id:true,
			mechanism_id: true
		}).limit(500).get()

		for (let i=0;i<curHasMec.data.length;i++) {
			let arr = curHasMec.data[i].subject_id
			arr.push('101331')
			arr.push('101381')
			arr.push('101771')
			arr.push('200260')
			
			const updateRes = await db.collection('mechanism-subject-list').where({
				_id:  curHasMec.data[i]._id
			}).update({
				subject_id: arr
			})
			console.log('更新成功!', updateRes)
		}


		// let successNum = 0
		// for (let s of mechinsmList.data) {
		// 	if (hasMecList.get(s._id)) {
		// 		const updateRes = await db.collection('mechanism-subject-list').where({
		// 			mechanism_id: s._id
		// 		}).update({
		// 			subject_id: subjectList
		// 		})
		// 		console.log('更新成功!', updateRes)
		// 	} else {
		// 		const addRes = await db.collection('mechanism-subject-list').add({
		// 			mechanism_id: s._id,
		// 			subject_id: subjectList
		// 		})
		// 		console.log('新增成功!', addRes)
		// 	}
		// 	successNum++
		// }
	}
	await openAllQlist()
	//返回数据给客户端
	return event
};
